package com.songtech.store.controller;

import com.github.pagehelper.PageInfo;
import com.songtech.base.common.BaseConstant;
import com.songtech.base.common.JsonResult;
import com.songtech.store.bean.Store;
import com.songtech.store.bean.StoreRecord;
import com.songtech.store.service.StoreRecordService;
import com.songtech.store.service.StoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: RENTIE
 * Date: 2018-06-19 11:20
 */
@RestController
@RequestMapping("/storerecord")
public class StoreRecordController {

    private final Logger logger = LoggerFactory.getLogger(StoreRecordController.class);

    @Autowired
    private StoreRecordService storeRecordService;

    @Autowired
    private StoreService storeService;

    /**
     *  出入库记录查询
     * @param map
     *   companyCode 厂商编号
     *   productCode 产品名称编号
     *   modelNumber 产品型号
     *  status 出入库状态，0表示入库，1表示出库
     *  startTime 操作开始时间
     *  endTime  操作结束时间
     *  page 当前页
     *  limit  每页显示个数
     * @return
     */
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public JsonResult queryStoreRecord(@RequestParam Map<String,String> map){
        PageInfo<StoreRecord> list=null;
        try {
           list= storeRecordService.selectStoreRecord(map);

        } catch (Exception e) {
            logger.error("出入库记录查询异常信息:"+e.getMessage(),e);
            return new JsonResult(null, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list.getList(), BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS,list.getTotal());
    }

    /**
     * 出入库记录详情查询
     * @param paramMap  查询条件封装map
     *          page（当前页）
     *           limit（每页个数）
     *           status  出入库状态
     *          operator 出入库操作人
     *          unitPrice 出入库单价
     * @return
     */
    @RequestMapping(value = "/detail" ,method = RequestMethod.GET)
    public JsonResult queryDetail(@RequestParam Map<String,String> paramMap){
        PageInfo<Store> list=null;
        try {
            list= storeService.selectRecordDetailsList(paramMap);

        } catch (Exception e) {
            logger.error("出入库记录详情查询异常信息:"+e.getMessage(),e);
            return new JsonResult(null, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list.getList(), BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS,list.getTotal());
    }

}
